<template>
    <div class="fail-box">
        <!--    头部操作    -->
        <div class="flex justify-between items-center">
            <div class="fail-box__tag">绘画失败</div>
            <div class="flex items-center">
                <el-tooltip
                    effect="dark"
                    content="重新生成"
                    placement="top"
                >
                    <img
                        class="w-[16px] h-[16px] ml-[16px] cursor-pointer"
                        :src="IconReload"
                        alt="重新生成"
                        @click="onReDrawing(value)"
                    />
                </el-tooltip>
                <el-tooltip effect="dark" content="删除" placement="top">
                    <img
                        class="w-[16px] h-[16px] ml-[16px] cursor-pointer"
                        :src="IconDelete"
                        alt="删除"
                        @click="deleteDrawing([value.id])"
                    />
                </el-tooltip>
            </div>
        </div>
        <el-image class="w-[100px] h-[96px] mt-[20px]" :src="ImageError" />
        <div class="text-xl mt-[20px] w-full">绘画失败</div>
        <el-popover
            placement="top"
            title=""
            effect="dark"
            :width="300"
            trigger="hover"
            :content="value"
        >
            <template #reference>
                <div
                    class="mt-[10px] text-base text-[#999999] px-[10px] h-[90px] line-clamp-5"
                >
                    错误信息：{{ value.failReason }}
                </div>
            </template>
        </el-popover>
        <div class="flex justify-between mt-[15px] text-[#999999] text-base">
            <span>时间：{{ value.createTime }}</span>
            <el-tag size="mini" v-if="value.modelName">{{ value.modelName }}</el-tag>
        </div>
    </div>
</template>

<script lang="ts" setup>
import ImageError from '~/assets/images/drawing/error.png'
import IconDelete from '~/assets/images/drawing/icon_delete.png'
import type { DrawingFormType } from '~/api/drawing'
import IconReload from 'assets/images/drawing/icon_reload.png'
import feedback from '~/utils/feedback'

const drawForm = inject<DrawingFormType>('drawForm')
const deleteDrawing = inject<(options: number[]) => void>('deleteDrawing')

const props = withDefaults(
    defineProps<{
        value?: any
    }>(),
    {
        value: {}
    }
)

const onReDrawing = async (drawing: any) => {
    try {
        // await feedback.confirm('确认要重新生成当前绘画吗？')
        drawForm.prompt = drawing.prompt
        drawForm.imageId = ''
        drawForm.other = drawing.promptOther
        drawForm.scale = drawing.scale
        drawForm.model = drawing.model
        drawForm.no_content = drawing.no_content
        drawForm.imageBase = drawing.imageBase
    } catch (error) {
        console.log('重新生成', error)
    }
}
</script>

<style lang="scss" scoped>
.fail-box {
    display: inline-block;
    width: 100%;
    height: 100%;
    padding: 15px 20px;
    text-align: center;

    &__tag {
        padding: 4px 8px;
        font-size: 14px;
        border-radius: 4px;
        color: #f63210;
        background: #ffefeb;
    }
}
</style>
